﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using grproLib;
using OurFAS.Data;

namespace OurFAS.MyReport
{
    class ReportHelper
    {
        public static void FillRecordToReport<T>(IGridppReport report, T myClass)
        {
            foreach (IGRField fld in report.DetailGrid.Recordset.Fields)
            {
                foreach (PropertyInfo pi in myClass.GetType().GetProperties())
                {
                    if (String.Compare(fld.RunningDBField, pi.Name, true) == 0)
                    {
                        report.DetailGrid.Recordset.Append();
                        fld.Value = pi.GetValue(myClass, null);
                        report.DetailGrid.Recordset.Post();
                    }
                }
            }
        }

        public static void FillRecordToReport(IGridppReport report,Dictionary<string,string> dict)
        {
            report.DetailGrid.Recordset.Append();
            foreach (IGRField fld in report.DetailGrid.Recordset.Fields)
            {
                foreach (KeyValuePair<string, string> kv in dict)
                {
                    if (String.Compare(fld.RunningDBField, kv.Key, true) == 0)
                    {
                        
                        fld.Value = kv.Value;
                        
                    }
                }
            }
            report.DetailGrid.Recordset.Post();
        }

        public static void FillRecordToReport(IGridppReport report, List<Dictionary<string, string>> dictList)
        {
            
            foreach (Dictionary<string, string> dict in dictList)
            {
                report.DetailGrid.Recordset.Append();
                foreach (IGRField fld in report.DetailGrid.Recordset.Fields)
                {
                    foreach (KeyValuePair<string, string> kv in dict)
                    {
                        if (String.Compare(fld.RunningDBField, kv.Key, true) == 0)
                        {
                            fld.Value = kv.Value;
                        }
                    }
                }
                report.DetailGrid.Recordset.Post();
            }
        }

        public static void PrintBaseAssetBarCode(Tbl_BaseAssets record)
        {
            Dictionary<string, string> reportDict = new Dictionary<string, string>();

            reportDict.Add("AssetBarCode", record.AssetTagCode);
            reportDict.Add("AssetName", record.AssetName);
            reportDict.Add("AssetDepartment", record.Dept);

            List<Dictionary<string, string>> dictList = new List<Dictionary<string, string>>();
            dictList.Add(reportDict);
            ReportPrintForm window = new ReportPrintForm(StringHelper.sReprotAssetBarcode, dictList);
            window.Show();
        }

        public static void PrintSelfAssetBarCode(Tbl_SelfAssets record)
        {
            Dictionary<string, string> reportDict = new Dictionary<string, string>();

            reportDict.Add("AssetBarCode", record.AssetTagCode);
            reportDict.Add("AssetName", record.AssetName);
            reportDict.Add("AssetDepartment", record.Dept);

            List<Dictionary<string, string>> dictList = new List<Dictionary<string, string>>();
            dictList.Add(reportDict);
            ReportPrintForm window = new ReportPrintForm(StringHelper.sReprotAssetBarcode, dictList);
            window.Show();
        }

        public static void PrintMeasureAssetBarCode(Tbl_MeasureAssets record)
        {
            Dictionary<string, string> reportDict = new Dictionary<string, string>();

            reportDict.Add("AssetBarCode", record.AssetTagCode);
            reportDict.Add("AssetName", record.AssetName);
            reportDict.Add("AssetDepartment", record.Dept);

            List<Dictionary<string, string>> dictList = new List<Dictionary<string, string>>();
            dictList.Add(reportDict);
            ReportPrintForm window = new ReportPrintForm(StringHelper.sReprotAssetBarcode, dictList);
            window.Show();
        }
    }
}
